package com.qf.service.impl;

import com.qf.exception.CustomerException;
import com.qf.mapper.UserMapper;
import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Random;

/**
 * @author zdl
 * @date 2025/2/15
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Override
    public User loginUser(User user,  HttpSession session) {

        //查询登录账号状态
        int i = userMapper.selectUserByUserName(user.getUsername());
        if (i != 1){
            throw  new CustomerException("70001","该用户已被禁用");
        }
        User user1 = userMapper.selectUserByUsernameAndPasswordAndRole(user);
        if (user1 == null){
            throw  new CustomerException("70002","账号或密码错误");
        }
        session.setAttribute("session",user);
        return user1;
    }

}
